const newsModel = require('../models/NewsModel')

const newsService = {
  getNews(data) {
    let { offset = 0, limit = 10 } = data
    return {
      find: newsModel.find().skip(Number(offset)).limit(Number(limit)).sort('-createdAt'),
      count: newsModel.countDocuments(),
    }
  },
  addNews(news) {
    return newsModel.create(news)
  },
  updateNews(_id, data) {
    return newsModel.updateOne(
      {
        _id,
      },
      {
        $set: data,
      }
    )
  },
  deleteNews(_id) {
    return newsModel.deleteOne({
      _id,
    })
  },
}

module.exports = newsService
